package BM1;
public class ListNode {
    public int val;
    public ListNode next = null;
    public ListNode(int val) {
      this.val = val;
    }
    /**
     * 根据可变参数一次性把链表串起来
     * 返回头结点，若 nums 为空则返回 null
     */
    public static ListNode buildList(int... nums) {
        if (nums == null || nums.length == 0) return null;
        ListNode head = new ListNode(nums[0]), cur = head;
        for (int i = 1; i < nums.length; i++) {
            cur.next = new ListNode(nums[i]);
            cur = cur.next;
        }
        return head;
    }
  }

